package com.titan.core.utils.data;


/**
 * @author 周成功
 * @email 86898837@qq.com
 * @date 2020年02月14日
 */
public class StringUtils {
    public static String append(Object...args) {
        if(args==null) {
            return "";
        }
        int len = args.length;
        if( len==0 ) {
            return "";
        } else if(len==1) {
            return FormatUtils.toString(args[0]);
        }
        int capacity = 16;
        for (int i = 0; i < len; i++) {
            if(args[i]==null) {
                continue;
            } else if(args[i] instanceof java.lang.String) {
                capacity = capacity + ((String)args[i]).length();
            } else {
                capacity = capacity + 8;
            }
        }
        StringBuilder buf = new StringBuilder(capacity);
        for (int i = 0; i < len; i++) {
            buf.append(FormatUtils.toString(args[i]));
        }
        return buf.toString();
    }   
    
    
    public static boolean isBlank(String str) {
        if( str == null ) {
            return true;
        }
        int strLen = str.length();
        if( strLen == 0 ) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }       
        return true;
    }
    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }
    

    public static boolean isEmpty(String str) {
        if( str == null || str.length() == 0 ) {
            return true;
        }
        return false;
    }
    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }
    
    
    public static boolean isNullOrEmpty(Object str) {
        if(str==null) {
            return true;
        } else {
            String value = FormatUtils.toString(str);
            if(value.length() == 0) {
                return true;
            } else {
                return false;
            }
        }
    }
    public static boolean isNotNullAndNotEmpty(Object str) {
        return !isNullOrEmpty(str);
    }
}
